package com.example.recyclerview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

//    private String[] data = {"ban", "ban", "ban", "ban", "ban", "ban",
//            "ban", "ban", "ban", "ban", "ban", "ban", "ban", "ban"};

    private List<Fruit> fruitList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initFruits();  //初始化水果数据

        RecyclerView recyclerView = findViewById(R.id.rv_1);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);

        //设置布局排列
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);

        recyclerView.setLayoutManager(layoutManager);
        FruitAdpater adpater = new FruitAdpater(fruitList);
        recyclerView.setAdapter(adpater);


    }

    private void initFruits(){
        for(int i =0;i <20;i++){
            Fruit ban = new Fruit("ban", R.drawable.ic_launcher_foreground);
            fruitList.add(ban);
        }
    }
}